package trend;
import java.io.*;
import java.util.*;

/* @Date 03 March 2008
 * @Author Hussein Patwa
 * Class to retrieve values from CSV file - Fixed row/colums
 */

@SuppressWarnings("all")
public class Csvinput{
        String[][] values;
        int rowNum, colNum;
        public Csvinput(File file,int rows, int cols){
            values = new String[rows][cols];
            //File file = new File("data.csv");
            try{
                BufferedReader bufRdr  = new BufferedReader(new FileReader(file));

                String line = null;
                int row = 0;
                int col = 0;

                // Read each line of the CSV file
                while((line = bufRdr.readLine()) != null)
                {
                    col = 0;
                    StringTokenizer st = new StringTokenizer(line,",");
                    while (st.hasMoreTokens())
                    {
                            // get next token and store it in the array
                            //String values;
                            values[row][col] = st.nextToken();
                            col++;
                    }
                    row++;
                }
                rowNum=row;
                colNum=col;
                // close the file
                bufRdr.close(); 
            }catch(IOException ex){    
        }
    } 
        
        public String[][] getValues(){
                return values;
        }
        public int getNumberOfRows(){
            return rowNum;
        }
        public int getNumberOfColumns(){
            return colNum;
        }
        
        public static void main(String[] args){
            Csvinput inObj = new Csvinput(new File("data.csv"),50,6);
            System.out.println(inObj.values.length);
            for(int i=0;i<5;i++)
                for(int j=0;j<5;j++)
            System.out.println(inObj.values[i][j]);
        }
}
